<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/11/5
 * Time: 10:39
 */
namespace app\admin\controller;
use think\Db;
class Record extends Base {
     public function index(){
         if(request()->isAjax()){
             extract(input());
             $map =array();
             $page = input('page') ? input('page'):1;
             $limit = input("limit")?input("limit"):10;// 获取总条数;
             if(isset($sex)&&$sex!="")
             {
                 $map['a.dk_status'] = $sex;
             }
             if(isset($start)&&$start!=""&&isset($end)&&$end=="")
             {
                 $map['a.dk_time'] = ['>= time',$start];
             }
             if(isset($end)&&$end!=""&&isset($start)&&$start=="")
             {
                 $map['a.dk_time'] = ['<= time',$end];
             }
             if(isset($start)&&$start!=""&&isset($end)&&$end!="")
             {
                 $map['a.dk_time'] = ['between time',[$start,$end]];
             }
             $count = Db::table('up_dk')->alias('a')
                 ->join('up_admin ua','ua.id = a.dk_user_id','left')
                 ->join('up_u_user ua1','ua1.user_id = a.user_id','left')
                 ->where($map)
                 ->count();
             $list = Db::table('up_dk')->alias('a')
                 ->join('up_admin ua','ua.id = a.dk_user_id','left')
                 ->join('up_u_user ua1','ua1.user_id = a.user_id','left')
                 ->where($map)
                 ->field('a.*,ua.username,ua1.user_username')
                 ->page($page, $limit)
                 ->order('a.dk_id desc')
                 ->select();//计算总页面
             foreach ($list as $key=>&$vo){
                 if($vo['dk_type'] == 1){
                     $vo['dk_type_name'] = '加';
                 }else{
                     $vo['dk_type_name'] = '减';
                 }
                 if($vo['dk_type_sex'] == 1){
                     $vo['dk_type_sex_name'] = '学生';
                 }else{
                     $vo['dk_type_sex_name'] = '老师';
                 }
             }
             return json(['code'=>220,'msg'=>'','count'=>$count,'data'=>$list]);
         }
         return $this->fetch();
     }

}